import 'dart:io';

import 'package:redis/redis.dart';

class Redis {

  late final Future<Command> conn;

  Redis(String ip, int port) {
    conn = RedisConnection().connect(ip, port);
  }

  void _sendByString(List cmd) {
    conn.then
      ((Command command){
      command.send_object(cmd).then
        ((var value) {
        print(value);
      });
    }).catchError((error) {
      switch (error.runtimeType) {
        case SocketException:
          print("Redis服务器不存在");
        case RedisError:
          print(error.e);

        default:
          print("其它问题   详细信息：");
          print(error);
      }
    });
  }

  void setValue(var key, var value) {
    _sendByString(["set",key,value]);
  }

  void getValue(var key) {
    _sendByString(["get",key]);
  }

}

void main () {
  Redis r = Redis("localhost",6379);
  r.getValue("a");
  r.getValue("a");
}